package com.wuh.controller;

import com.github.pagehelper.PageInfo;
import com.wuh.model.ClassInfor;
import com.wuh.model.ClassSignUp;
import com.wuh.model.User;
import com.wuh.service.ClassInforService;
import com.wuh.service.ClassSignUpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * 公开课报名表(ClassSignUp)表控制层
 */
@Controller
public class ClassSignUpController {
    /**
     * 服务对象
     */
    @Resource
    private ClassSignUpService classSignUpService;

    @Autowired
    private ClassInforService classInforService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public ClassSignUp selectOne(Integer id) {
        return this.classSignUpService.queryById(id);
    }

    /**
     * 跳转用户我的公开课 并且加载数据
     *
     * @param classSignUp
     * @param session
     * @return
     */
    @RequestMapping("/queryUserClass")
    public String queryClassSignUpAll(ClassSignUp classSignUp,ClassInfor classInfor, HttpSession session) {
        //加载最新公开课数据
        PageInfo<ClassInfor> newClassInfor = classInforService.queryClassAllByDate(classInfor);
//        System.err.println("加载的最新公开课newClassInfor：" + newClassInfor);
        session.setAttribute("newClassInfor", newClassInfor);
        //获取登录用户id
        User user = (User) session.getAttribute("sess_user");
        Integer user_id = user.getUser_id();
        classSignUp.setUserId(user_id);
        //加载用户我的公开课
        PageInfo<ClassSignUp> classSignUpPageInfo = classSignUpService.queryClassSignUpAll(classSignUp);

        session.setAttribute("UserClass", classSignUpPageInfo);
        return "person/user_myclass";
//        return "test";
    }




    /**
     * 报名支付页面跳转
     * @return
     */
    @RequestMapping("/toClassPayment1")
    public  String toClassPayment1(ClassSignUp classSignUp){
        classSignUpService.addClassSignUp(classSignUp);
        return "payment/classpayment_1";
    }
    @RequestMapping("/toClassPayment2")
    public  String toClassPayment2(){
        return "payment/classpayment_2";
    }

    @RequestMapping("/toClassPayment3")
    public String toClassPayment3() {
        return "payment/classpayment_3";
    }

}